package com.kaishengit.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Goal;
import com.kaishengit.util.web.ServletUtil;


public class GoalEdit extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		String id = request.getParameter("id");
		GoalService service = new GoalService();
		Goal goal = service.findById(id);
		request.setAttribute("goal", goal);
		
		ServletUtil.forward(request, response, "goal_edit");
		
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html");
		
		String id = request.getParameter("id");
		String name = request.getParameter("goalname");
		String desc = request.getParameter("goaldesc");
		
		GoalService service = new GoalService();
		Goal goal = service.findById(id);
		goal.setName(name);
		goal.setDesc(desc);
		
		service.update(goal);
		ServletUtil.redirect(response, "goallist.jspx");
	}

}
